<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">表单操作</h4>
            </div>
            <div class="modal-body" id="addBodyId">
            	
            	
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="addSubmitId" class="btn btn-primary" >提交更改</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
(function(){
	var basePath = "${pageContext.request.contextPath}"
	$("#addBodyId").loadFormHtmlData({
		formBodyId: 'addBodyId',
		tableNameId: 'tableNameId',
		backFunction: function(obj){
			
		}
	});
	$("#addSubmitId").on("click",function(){
		$(this).addOrUpdate({
			url: basePath + "/dynamicForm/dynamicFormAction.do?method=addOrUpdateModel",
			addBodyId: "addBodyId",
			addOrUpdateModal: "addModal",
			tableNameId: "tableNameId",
			backFunction: function(obj){
				
			}
		});
	});
	
	/* var basePath = "${pageContext.request.contextPath}";
	function addOrUpdate(){
		var url = basePath + "/dynamicForm/dynamicFormAction.do?method=addModel";
		var params = {};
		var s = $("#addBodyId").hzValidate("init");
		if(s == true){
			 var json = OAajaxSubmit("addBodyId");
			 params = {
					 "name": $("#tableNameId").data("tableNameData"),
					 "jsonStr": JSON.stringify(json)
			 }
			 $.post(url,params,function(data){
				 var reJSon = jQuery.parseJSON(data);
				 if(reJSon.status == 1){
					 var json = {
								'start': 0,
								'limit': 20
						};
						var dataGrid = {
								"name": $("#tableNameId").data("tableNameData"),
								"jsonStr":JSON.stringify(json)
						};
					 $("#addModal").modal("hide");
					 $(this).loadGrid(dataGrid);
				 }
				 console.log(reJSon);
				 alert(reJSon.msg);
			 });
		}
		
	}
	function loadFormData(){
		
		$("#addBodyId").html("");
		
		var json = $("#tableNameId").data("formData");
		var formJson = jQuery.parseJSON(json.table_info);
		
		for(var i = 0;i < formJson.length;i++){
			
			var type = formJson[i].type;
			var _parentDiv = document.createElement("div");
			var _childSpan = document.createElement("span");
			var _childDiv = document.createElement("div");
			
			_parentDiv.setAttribute("class","input-group");
			_parentDiv.setAttribute("style","margin-bottom:5px;");
			_childSpan.setAttribute("class","input-group-addon");
			_childSpan.setAttribute("style","width: 100px;");
			_childSpan.textContent = formJson[i].name;
			_childDiv.setAttribute("class","dropdown");
			_childDiv.setAttribute("style","height: 37px;width: 300px;");
			
			
			if(type == 'text'){
				var _input = document.createElement("input");
				_input.setAttribute("id",formJson[i].column);
				_input.setAttribute("name",formJson[i].column);
				_input.setAttribute("type","text");
				_input.setAttribute("style","width: 300px;height: 37px;");
				_input.setAttribute("value",formJson[i].val);
				_childDiv.appendChild(_input);
			}
			if(type == 'textArea'){
				var _textArea = document.createElement("textArea");
				_textArea.setAttribute("id",formJson[i].column);
				_textArea.setAttribute("name",formJson[i].column);
				_textArea.setAttribute("style","width: 300px;height: 37px;");
				_textArea.setAttribute("value",formJson[i].val);
				_childDiv.appendChild(_textArea);
			}
			
			if(type.indexOf("select") != -1){
				var _select = document.createElement("select");
				_select.setAttribute("id",formJson[i].column);
				_select.setAttribute("name",formJson[i].column);
				_select.setAttribute("style","width: 300px;height: 37px;");
				if(type.indexOf("multiple") != -1){
					_select.setAttribute("multiple","multiple");
				}
				var vals = new Array();
				if(formJson[i].val.indexOf(",") != -1){
					vals = formJson[i].val.split(",");
				}else{
					vals[0] = formJson[i].val;
				}
				for(var j = 0;j < vals.length-1;j++){
					var _options = document.createElement("option");
					if(vals[j].indexOf(":") != -1 && !jQuery.isEmptyObject(vals[j])){
						_options.setAttribute("value",vals[j].split(":")[0]);
						_options.textContent = vals[j].split(":")[1];
					}else{
						_options.setAttribute("value",vals[j]);
						_options.textContent = vals[j];
					}
					_select.appendChild(_options);
				}
				_childDiv.appendChild(_select);
			}
			
			if(type.indexOf('checkbox') != -1){
				var arr = new Array();
				if(formJson[i].val.indexOf(",") != -1){
					arr = formJson[i].val.split(",");
				}else{
					arr[0] = formJson[i].val;
				}
				for(var j = 0;j < arr.length - 1;j++){
					var _input = document.createElement("input");
					//_input.setAttribute("id",formJson[i].column);
					_input.setAttribute("name",formJson[i].column);
					_input.setAttribute("type","checkbox")
					var textNode;
					if(arr[j].indexOf(":") != -1){
						_input.setAttribute("value",arr[j].split(":")[0]);
						textNode = document.createTextNode(arr[j].split(":")[1]); 
					}else{
						_input.setAttribute("value",arr[j].split(":"));
						 textNode = document.createTextNode(arr[j].split(":")); 
					}
					_input.setAttribute("style","margin-left:10px;");
					_childDiv.appendChild(_input);
					_childDiv.appendChild(textNode);
					
					if(type.indexOf("inline") == -1){
						var _br = document.createElement("br");
						_childDiv.appendChild(_br);
					}
				}
			}
			if(type.indexOf('radio') != -1){
				var arr = new Array();
				if(formJson[i].val.indexOf(",") != -1){
					arr = formJson[i].val.split(",");
				}else{
					arr[0] = formJson[i].val;
				}
				for(var j = 0;j < arr.length - 1;j++){
					var _input = document.createElement("input");
					//_input.setAttribute("id",formJson[i].column);
					_input.setAttribute("name",formJson[i].column);
					_input.setAttribute("type","radio")
					var textNode;
					if(arr[j].indexOf(":") != -1){
						_input.setAttribute("value",arr[j].split(":")[0]);
						textNode = document.createTextNode(arr[j].split(":")[1]); 
					}else{
						_input.setAttribute("value",arr[j].split(":"));
						 textNode = document.createTextNode(arr[j].split(":")); 
					}
					_input.setAttribute("style","margin-left:10px;");
					_childDiv.appendChild(_input);
					_childDiv.appendChild(textNode);
					
					if(type.indexOf("inline") == -1){
						var _br = document.createElement("br");
						_childDiv.appendChild(_br);
					}
				}
			}
			_parentDiv.appendChild(_childSpan);
			_parentDiv.appendChild(_childDiv);
			
			$("#addBodyId").append(_parentDiv);
		}
	}
	
	$("#addSubmitId").on("click",function(){
		addOrUpdate();
	});
	$(function(){
		loadFormData();
	}); */
})();
</script>